﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;

using DAL;

namespace WS
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public XmlDocument GetStoresInfo()
        {

            using (AWCDataContext awcDC = new AWCDataContext())
            {
                XElement stores = new XElement("Stores",
                                      from s in awcDC.Stores
                                      join ca in awcDC.CustomerAddresses
                                      on s.CustomerID equals ca.CustomerID
                                      where ca is CustomerAddress &&
                                          /*AdressTypeID = main office */
                                     (ca.AddressTypeID == 3)
                                      select new XElement("Store",
                                          new XElement("id", s.CustomerID),
                                          new XElement("name", s.Name)));
                                          //ca.Address.PostalCode,);
                //XmlWriter storereader = stores.CreateWriter();
                //stores.WriteTo(storereader);
                //XmlNode xml = 
                XmlDocument storesxml = new XmlDocument();
                storesxml.Load(stores.CreateReader());
                return storesxml;


            }
            
            
        }


    }
}
